package com.school.entity.dto;

import io.swagger.v3.oas.annotations.media.Schema;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 登录响应DTO
 * 
 * @author School Development Team
 * @version 1.0.0
 * @since 2024
 */
@Schema(description = "登录响应")
public class LoginResponse implements Serializable {

    private static final long serialVersionUID = 1L;

    @Schema(description = "访问令牌", example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...")
    private String accessToken;

    @Schema(description = "刷新令牌", example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...")
    private String refreshToken;

    @Schema(description = "令牌类型", example = "Bearer")
    private String tokenType = "Bearer";

    @Schema(description = "过期时间(秒)", example = "7200")
    private Long expiresIn;

    @Schema(description = "用户信息")
    private UserInfo userInfo;

    public LoginResponse() {
    }

    public LoginResponse(String accessToken, String refreshToken, Long expiresIn, UserInfo userInfo) {
        this.accessToken = accessToken;
        this.refreshToken = refreshToken;
        this.expiresIn = expiresIn;
        this.userInfo = userInfo;
    }

    @Schema(description = "用户基本信息")
    public static class UserInfo implements Serializable {
        
        private static final long serialVersionUID = 1L;

        @Schema(description = "用户ID", example = "1")
        private String userId;

        @Schema(description = "用户名", example = "admin")
        private String username;

        @Schema(description = "用户类型", example = "admin")
        private String userType;

        @Schema(description = "关联ID", example = "T001")
        private String relatedId;

        @Schema(description = "邮箱", example = "admin@school.edu")
        private String email;

        @Schema(description = "电话", example = "13800138000")
        private String phone;

        @Schema(description = "状态", example = "active")
        private String status;

        @Schema(description = "最后登录时间")
        private LocalDateTime lastLoginTime;

        @Schema(description = "登录次数", example = "10")
        private Integer loginCount;

        public UserInfo() {
        }

        public UserInfo(String userId, String username, String userType, String relatedId, 
                       String email, String phone, String status, LocalDateTime lastLoginTime, Integer loginCount) {
            this.userId = userId;
            this.username = username;
            this.userType = userType;
            this.relatedId = relatedId;
            this.email = email;
            this.phone = phone;
            this.status = status;
            this.lastLoginTime = lastLoginTime;
            this.loginCount = loginCount;
        }

        // Getter和Setter方法
        public String getUserId() {
            return userId;
        }

        public void setUserId(String userId) {
            this.userId = userId;
        }

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getUserType() {
            return userType;
        }

        public void setUserType(String userType) {
            this.userType = userType;
        }

        public String getRelatedId() {
            return relatedId;
        }

        public void setRelatedId(String relatedId) {
            this.relatedId = relatedId;
        }

        public String getEmail() {
            return email;
        }

        public void setEmail(String email) {
            this.email = email;
        }

        public String getPhone() {
            return phone;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public LocalDateTime getLastLoginTime() {
            return lastLoginTime;
        }

        public void setLastLoginTime(LocalDateTime lastLoginTime) {
            this.lastLoginTime = lastLoginTime;
        }

        public Integer getLoginCount() {
            return loginCount;
        }

        public void setLoginCount(Integer loginCount) {
            this.loginCount = loginCount;
        }

        @Override
        public String toString() {
            return "UserInfo{" +
                    "userId='" + userId + '\'' +
                    ", username='" + username + '\'' +
                    ", userType='" + userType + '\'' +
                    ", relatedId='" + relatedId + '\'' +
                    ", email='" + email + '\'' +
                    ", phone='" + phone + '\'' +
                    ", status='" + status + '\'' +
                    ", lastLoginTime=" + lastLoginTime +
                    ", loginCount=" + loginCount +
                    '}';
        }
    }

    // Getter和Setter方法
    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public String getRefreshToken() {
        return refreshToken;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    public String getTokenType() {
        return tokenType;
    }

    public void setTokenType(String tokenType) {
        this.tokenType = tokenType;
    }

    public Long getExpiresIn() {
        return expiresIn;
    }

    public void setExpiresIn(Long expiresIn) {
        this.expiresIn = expiresIn;
    }

    public UserInfo getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(UserInfo userInfo) {
        this.userInfo = userInfo;
    }

    @Override
    public String toString() {
        return "LoginResponse{" +
                "accessToken='[PROTECTED]'" +
                ", refreshToken='[PROTECTED]'" +
                ", tokenType='" + tokenType + '\'' +
                ", expiresIn=" + expiresIn +
                ", userInfo=" + userInfo +
                '}';
    }
}